package cn.walls1717.mall.modules.pms.service.impl;

import cn.walls1717.mall.modules.pms.dto.PageListDTO;
import cn.walls1717.mall.modules.pms.dto.ProductAttributeCateDTO;
import cn.walls1717.mall.modules.pms.model.PmsProductAttributeCategory;
import cn.walls1717.mall.modules.pms.mapper.PmsProductAttributeCategoryMapper;
import cn.walls1717.mall.modules.pms.service.PmsProductAttributeCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 产品属性分类表 服务实现类
 * </p>
 *
 * @author walls1717
 * @since 2022-04-09
 */
@Service
public class PmsProductAttributeCategoryServiceImpl extends ServiceImpl<PmsProductAttributeCategoryMapper, PmsProductAttributeCategory> implements PmsProductAttributeCategoryService {

    private final PmsProductAttributeCategoryMapper attributeCategoryMapper;
    @Autowired
    public PmsProductAttributeCategoryServiceImpl(PmsProductAttributeCategoryMapper attributeCategoryMapper) {
        this.attributeCategoryMapper = attributeCategoryMapper;
    }

    @Override
    public Page<PmsProductAttributeCategory> pageList(PageListDTO pageListDTO) {
        Page<PmsProductAttributeCategory> page = new Page<>(pageListDTO.getPageNum(), pageListDTO.getPageSize());
        this.page(page);
        return page;
    }

    @Override
    public boolean createAttributeCategory(PmsProductAttributeCategory pmsProductAttributeCategory) {
        // 初始化属性数量
        pmsProductAttributeCategory.setAttributeCount(0);
        // 初始化参数数量
        pmsProductAttributeCategory.setParamCount(0);
        return this.save(pmsProductAttributeCategory);
    }

    @Override
    public List<ProductAttributeCateDTO> listWithAttr() {
        return attributeCategoryMapper.listWithAttr();
    }
}
